<?php
/**
 * @file functicons.php(皮肤调用的函数)
 * @package Japan-Style
 */
?>
<?php

remove_action('wp_head', 'wp_generator');
remove_action('wp_head', 'wlwmanifest_link');

if (function_exists('register_sidebar') )
	register_sidebar(array(
	    'name' => 'sidebar1',
        'before_widget' => '<div class="block">',
        'after_widget' => '</div>',
        'before_title' => '<h4 class="widgettitle">',
        'after_title' => '</h4>',
        ));
if (function_exists('register_sidebar') )
	register_sidebar(array(
	    'name' => 'sidebar2',
        'before_widget' => '<div class="block">',
        'after_widget' => '</div>',
        'before_title' => '<h4 class="widgettitle">',
        'after_title' => '</h4>',
        ));
if (function_exists('register_sidebar') )
	register_sidebar(array(
	    'name' => '我的圈子',
        'before_widget' => '<div class="block">',
        'after_widget' => '</div>',
        'before_title' => '<h4 class="widgettitle">',
        'after_title' => '</h4>',
        ));

// 获得最近留言
function simple_recent_comments($src_count=7, $src_length=60,$post_HTML='</li>') {
	global $wpdb;
	
	$sql = "SELECT DISTINCT ID, post_title, post_password, comment_ID, comment_post_ID, comment_author, comment_date_gmt, comment_approved, comment_type, 
			SUBSTRING(comment_content,1,$src_length) AS com_excerpt 
		FROM $wpdb->comments 
		LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID = $wpdb->posts.ID) 
		WHERE comment_approved = '1' AND comment_type = '' AND post_password = '' 
		ORDER BY comment_date_gmt DESC 
		LIMIT $src_count";
	$comments = $wpdb->get_results($sql);

	//$output = $pre_HTML;
	$output .= "";
	foreach ($comments as $comment) {
		$output .= "\n\t<li><a href=\"" . get_permalink($comment->ID) . "#comment-" . $comment->comment_ID  . "\" rel=\"bookmark\" title=\"on " . $comment->post_title . "\"><b>" . $comment->comment_author . "</b>:&nbsp;&nbsp;" . strip_tags($comment->com_excerpt) . "...</a></li>";
	}
	$output .= "";
	$output .= $post_HTML;
	
	echo $output;
}

// 获得热评文章
function simple_get_most_viewed($posts_num=10, $days=30){
	global $wpdb;
	
	$sql = "SELECT `ID` , `post_title` , `comment_count` FROM $wpdb->posts
			WHERE `post_type` = 'post' AND TO_DAYS( now( ) ) - TO_DAYS( `post_date` ) < $days
			ORDER BY `comment_count` DESC LIMIT 0 , $posts_num ";

	$posts = $wpdb->get_results($sql);
	$output = "";
	foreach ($posts as $post){
		$output .= "\n<li><a href=\"".get_permalink($post->ID)."\" rel=\"bookmark\" title=\"".$post->post_title."\" >".$post->post_title."</a> - ".$post->comment_count."个评论</li>";
	}
	echo $output;
}
?>